﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace Light.Framework
{
    /// <summary>
    /// 数据库外键字段映射特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Property)]
    public class BelongsAttribute : Attribute
    {
        /// <summary>
        /// 数据库列名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        ///  join表连接方式
        /// </summary>
        public JoinBehaviour JoinBehaviour { get; set; }

        /// <summary>
        /// 递归深度，从当前属性类型开始算，向上级查找，默认值 0，不递归
        /// 如 obj.Parent 算0，obj.Parent.Parent 算 1
        /// </summary>
        public int RecursiveDeep { get; set; }

        /// <summary>
        /// 是否只用于查询，不保存此值
        /// </summary>
        public bool ReadOnly { get; set; }

        /// <summary>
        /// 构造函数(默认递归深度1)
        /// </summary>
        /// <param name="name">数据库列名</param>
        public BelongsAttribute(string name)
        {
            RecursiveDeep = 0;
            Name = name;
        }
    }

    /// <summary>
    /// 当关联的数据找不到时的处理方式
    /// </summary>
    public enum JoinBehaviour
    {

        /// <summary>
        /// 默认(左连接)
        /// </summary>
        Defalut = 0,

        /// <summary>
        /// 左连接
        /// </summary>
        Left = 1,

        /// <summary>
        /// 内连接
        /// </summary>
        Inner = 2,
    }
}
